import request from "@/utils/request";
import type { AddressDTO, AddressVO } from "@/types/addressType";
import type { Response } from "@/types/response";

enum ENUM {
   fetchAddressListAPI = "/member/address",
   addAddressAPI = "/member/address",
   deleteAddressAPI = "/member/address",
   findAddressDetailAPI = "/member/address",
   updateAddressAPI = "/member/address"
}

/**
 * @description 获取收货地址列表的接口
 * */
export const fetchAddressListAPI = (): Promise<Response<AddressVO[]>> => request<AddressVO[]>({
   url: ENUM.fetchAddressListAPI,
   method: "GET",
});

/**
 * @description 新增收货地址列表的接口
 * */
export const addAddressAPI = (data: AddressDTO): Promise<Response<{ id: number }>> => request<{ id: number }>({
   url: ENUM.addAddressAPI,
   method: "POST",
   data,
});

/**
 * @description 删除收货地址的接口
 * */
export const deleteAddressAPI = (id: string): Promise<Response<{ id: number }>> => request<{ id: number }>({
   url: `${ENUM.deleteAddressAPI}/${id}`,
   method: "DELETE",
});

/**
 * @description 获取收货地址详情的接口
 * */
export const findAddressDetailAPI = (id: string): Promise<Response<AddressVO>> => request<AddressVO>({
   url: `${ENUM.findAddressDetailAPI}/${id}`,
   method: "GET",
});

/**
 * @description 修改收货地址的接口
 * */
export const updateAddressAPI = (id: string, data: AddressDTO) => request({
   url: `${ENUM.updateAddressAPI}/${id}`,
   method: "PUT",
   data,
});